<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function Cat(name, age) {
        this.name = name;
        // 伪造继承：用当前对象this去伪造父类构造器中的this
        Animal.call(this, age);
      }
     // 原型继承核心： 子类.prototype = 父类.prototype
      Cat.prototype = Animal.prototype
      // 子类原型重新只有，其原本的constructor也会被覆盖，所以为了原型链的一个完整性
      // 需要修复constructor的属性,让程序更加健壮
      Cat.prototype.constructor = Cat
      function Animal(age) {
        this.age = age;
      }
      Animal.prototype.eat =function(){
        console.log('chi')
      }
      var p = new Cat('lisi', 18);
      console.log(p);
      p.eat()
      console.log(Cat.prototype.constructor === Cat)
    </script>
  </body>
</html>
